package com.buercorp.wangyu.core1.ch12.threads;

/**
 * 可见性和有序性
 * 多线程提高效率，本地缓存数据，造成数据修改不可见
 * 要想保证可见 要么出发同步指令 要么加上 volatile 被修饰的内存 只要有修改 马上同步涉及到每个线程
 *
 * @auter liyiyu
 */

import javax.naming.Name;

public class ThreadText10 {
    volatile boolean running = true;

    void run() {
        System.out.println("run start");
        while (running) {
            System.out.println("hello, running: "+running);
        }
        System.out.println("run end");
    }


    public static void main(String[] args) throws InterruptedException {
        ThreadText10 t = new ThreadText10();
        Thread thread = new Thread(() -> {
            t.run();
        });
        thread.start();
        thread.sleep(10000);

        System.out.println("thread.sleep(1000); end");
        t.running = false;

        System.out.println("main thread: "+t.running);

    }


}
